from django.test import TestCase
from myapp.models import MyModel

class MyModelTest(TestCase):
    def setUp(self):
        # 设置测试环境，例如创建测试数据
        MyModel.objects.create(name='Test Model')

    def test_model_creation(self):
        # 测试模型创建
        model = MyModel.objects.get(name='Test Model')
        self.assertEqual(model.name, 'Test Model')
from django.test import TestCase, Client
from django.urls import reverse

class MyViewTest(TestCase):
    def setUp(self):
        # 设置测试环境，例如创建测试客户端
        self.client = Client()

    def test_home_view(self):
        # 测试视图
        response = self.client.get(reverse('home'))
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'about.html')
